package com.jt.travel.store.controller;

import com.jt.travel.store.service.TRouteService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

@Controller
@RequestMapping("/route")
public class TRouteController {
    @Resource
    private TRouteService tRouteService;

    @GetMapping("/getByPage")
    @ResponseBody
    public Map getRouteByPage(@RequestParam(value = "currentPage", defaultValue = "1") Integer currentPage,
                              @RequestParam(value = "pageSize", defaultValue = "6") Integer pageSize,
                              @RequestParam(value = "category_id", defaultValue = "1") Integer category_id,
                              @RequestParam(value = "route_name", required = false) String route_name
    ) {
        if (route_name.equals("")){
            route_name=null;
        }
        Map routeListByPage = tRouteService.getRouteListByPage(currentPage, pageSize, category_id, route_name);
        Integer count=tRouteService.selectRoutePageCount(category_id,route_name);
        routeListByPage.put("total",count);
        routeListByPage.put("status",200);
        return routeListByPage;
    }
    @GetMapping("/getById")
    @ResponseBody
    public Map getById(@RequestParam("id") Integer id){
        Map routeListByid=tRouteService.getById(id);
        routeListByid.put("status",200);
        return routeListByid;
    }
    @GetMapping("/getImgsById")
    @ResponseBody
    public Map getImgsById(@RequestParam("id") Integer routeId){
        Map getImgsById=tRouteService.getImgsById(routeId);
        getImgsById.put("status",200);
        return getImgsById;
    }
}
